//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Web;
using System.Web.UI;

using CommunityServer.Components;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{
    /// <summary>
    /// Summary description for PostAttachment.
    /// </summary>
    public class DownloadPostAttachment : Control 
    {
        CSContext csContext = CSContext.Current;

        protected override void OnLoad(System.EventArgs e)
        {
            // Get the forum the attachment is in
            //
            Forum forum = Forums.GetForumByPostID(csContext.PostID, csContext.User.UserID, false);

            if (forum == null) 
            {
                throw new CSException(CSExceptionType.SectionNotFound, csContext.SectionID.ToString());
            }

            // Get the ForumPermission
            //
            ForumPermission permission = forum.ResolvePermission( csContext.User ) as ForumPermission;

            // if user is not allowed to read this post, return
            //
            if (!permission.Read ) 
            {
                throw new CSException(CSExceptionType.GeneralAccessDenied, csContext.SectionID.ToString());
            }

			ForumAttachmentSettings fas = ForumConfiguration.Instance().AttachmentSettings;
			fas.HandleHttpRequest(this.Context, forum);
            System.Web.HttpContext.Current.Response.End();
        }

    }
}
